﻿using BW.Demo.Domain.Entities;
using BW.Demo.ErrorCode;
using BW.Demo.Infrastructure.Interfcaes;
using BW.Demo.WebApi.Applications.Commands.Deputy;
using MediatR;

namespace BW.Demo.WebApi.Applications.CommandHandlers.Deputy
{
    public class AquacultureQueryCommandHandler : IRequestHandler<AquacultureQueryCommand, APIResult<List<Aquaculture>>>
    {
        IBaseRespitory<Aquaculture> _respitory;
        public AquacultureQueryCommandHandler(IBaseRespitory<Aquaculture> _respitory)
        {
            this._respitory = _respitory;
        }
        public Task<APIResult<List<Aquaculture>>> Handle(AquacultureQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Aquaculture>> result=new APIResult<List<Aquaculture>>();
            result.Code=ResultCode.查询成功;
            result.Message=ResultCode.查询成功.ToString();
            var list=_respitory.GetAll().Where(x=>x.Batch==request.Batch);
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
